# -*- coding: utf-8 -*-
import scrapy
import json

class A163NewsSpider(scrapy.Spider):
    name = '163_news'
    allowed_domains = ['163.com']
    start_urls = ['http://mobile.163.com/special/index_datalist/?callback=data_callback']

    def parse(self, response):
        list = response.text[15:-2].replace(" ","").replace("\n","").replace("\t","").split('title')
        num = len(list)
        print(num)
        for i, content in enumerate(list):
            if i == num-1:
                result = '{"title' + content
            elif i > 0:
                result = '{"title' + content[:-3]
            else:
                result = None
            #print(result)
            if result != None:
                dict = json.loads(result)
                print(dict)